//#include <stdio.h>
//#include <stdlib.h>
//#include <string.h>
//
//#define HASH_SIZE 100003 
//
//int main()
//{
//    int T;
//    scanf_s("%d", &T); 
//
//    while (T--) 
//    {
//        int n;
//        scanf_s("%d", &n); 
//
//        int* a = (int*)malloc(n * sizeof(int)); 
//        int* b = (int*)malloc(n * sizeof(int)); 
//        int count = 0; 
//
//        int used[HASH_SIZE];
//        long long table[HASH_SIZE]; 
//        memset(used, 0, sizeof(used)); 
//
//        for (int i = 0; i < n; i++) 
//        {
//            scanf_s("%d", &a[i]);
//        }
//
//        for (int i = 0; i < n; i++) 
//        {
//            int x = a[i];
//            int idx = x % HASH_SIZE;
//            if (idx < 0) idx += HASH_SIZE;
//
//            while (used[idx]) 
//            {
//                if (table[idx] == x) break;
//                idx = (idx + 1) % HASH_SIZE; 
//            }
//
//            if (!used[idx])
//            {
//                used[idx] = 1;     
//                table[idx] = x; 
//                b[count++] = x; 
//            }
//        }
//
//        for (int i = 0; i < count; i++) 
//        {
//            if (i > 0) printf(" ");
//            printf("%d", b[i]);
//        }
//        printf("\n");
//
//        free(a);
//        free(b);
//    }
//
//    return 0;
//}

#include <stdio.h>
#include <stdlib.h>

#define MAX_SIZE 1000010

typedef struct 
{
    int* heap;    
    int capacity; 
    int size;     
} MinHeap;

MinHeap* createMinHeap(int capacity) 
{
    MinHeap* heap = (MinHeap*)malloc(sizeof(MinHeap));
    heap->capacity = capacity;
    heap->size = 0;
    heap->heap = (int*)malloc(capacity * sizeof(int));
    return heap;
}

void swap(int* a, int* b) 
{
    int temp = *a;
    *a = *b;
    *b = temp;
}

void swim(MinHeap* heap, int index)
{
    while (index > 0 && heap->heap[(index - 1) / 2] > heap->heap[index]) 
    {
        swap(&heap->heap[(index - 1) / 2], &heap->heap[index]);
        index = (index - 1) / 2;
    }
}

void sink(MinHeap* heap, int index) 
{
    int smallest = index;
    int left = 2 * index + 1;
    int right = 2 * index + 2;

    if (left < heap->size && heap->heap[left] < heap->heap[smallest]) {
        smallest = left;
    }

    if (right < heap->size && heap->heap[right] < heap->heap[smallest]) {
        smallest = right;
    }

    if (smallest != index) {
        swap(&heap->heap[index], &heap->heap[smallest]);
        sink(heap, smallest);
    }
}

void insert(MinHeap* heap, int x) 
{
    if (heap->size == heap->capacity) 
    {
        heap->capacity *= 2;
        heap->heap = (int*)realloc(heap->heap, heap->capacity * sizeof(int));
    }
    heap->heap[heap->size] = x;
    swim(heap, heap->size);
    heap->size++;
}

int getMin(MinHeap* heap) 
{
    if (heap->size == 0) return -1; 
    return heap->heap[0];
}

void deleteMin(MinHeap* heap)
{
    if (heap->size == 0) return; 
    heap->heap[0] = heap->heap[heap->size - 1];
    heap->size--;
    sink(heap, 0);
}

int main() 
{
    int n;
    scanf_s("%d", &n);

    MinHeap* heap = createMinHeap(n);

    for (int i = 0; i < n; i++) 
    {
        int op;
        scanf_s("%d", &op); 

        if (op == 1) 
        {
            int x;
            scanf_s("%d", &x);
            insert(heap, x);
        }
        else if (op == 2) 
        {
            printf("%d\n", getMin(heap));
        }
        else if (op == 3) 
        {
            deleteMin(heap);
        }
    }

    free(heap->heap);
    free(heap);

    return 0;
}